//
//  BaseViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/10.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = COLOR_OF_WHITE;
    
    if (self.navigationController.viewControllers.count > 1) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
//        self.navigationController.navigationBar.barTintColor = COLOR_OF_WHITE;
//        [self.leftButton setImage:[UIImage imageNamed:@"back_b"] forState:UIControlStateNormal];
    } else {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
//        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
//        self.navigationController.navigationBar.barTintColor = THEMECOLOR_OF_RED;
//        [self.leftButton setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal];
    }
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    if (self.navigationController.viewControllers.count > 1) {
        self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.leftButton.frame = CGRectMake(0, 0, 44, 44);
//        self.leftButton.imageEdgeInsets = UIEdgeInsetsMake(11, 0, 12, 32);
        [self.leftButton setImage:[UIImage imageNamed:@"back_b"] forState:UIControlStateNormal];
        [self.leftButton addTarget:self action:@selector(customBackButtonTap) forControlEvents:UIControlEventTouchUpInside];
        
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
        self.navigationItem.leftBarButtonItem = backItem;
    }
    
    
    self.noDataView = [[NoDataView alloc] initWithFrame:CGRectMake(0, 50*Scale, WIDTH, HEIGHT-HeightOfTabBar-200*Scale)];
    self.noDataView.userInteractionEnabled = YES;
    self.noDataView.hidden = YES;
    [self.view addSubview:self.noDataView];
    [self.noDataView addTarget:self action:@selector(noNetButtonTap) forControlEvents:UIControlEventTouchUpInside];
}

- (void)customBackButtonTap {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)noNetButtonTap {
    
}
- (void)callTel:(NSString *)tel {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", tel]]];
}

//- (UIStatusBarStyle)preferredStatusBarStyle {
//    return UIStatusBarStyleDefault;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
